cmake_minimum_required(VERSION 3.13)

project(Spark)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option(BUILD_SHARED "Building shared library" OFF)
option(BUILD_TEST "Building test case" ON)
option(GTEST_UNITTEST "Build gtest unittests" ON)

find_package(Threads REQUIRED)

include(GNUInstallDirs)

include_directories(
    ${PROJECT_NAME}
    PUBLIC
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
    PRIVATRE
        ${PROJECT_SOURCE_DIR}
        ${PROJECT_SOURCE_DIR}/Spark/Utils
        ${PROJECT_SOURCE_DIR}/Spark/Net
        ${PROJECT_SOURCE_DIR}/Spark/Net/Impl
)

add_library(spark-net STATIC "")
add_subdirectory(Spark/Net)

add_library(spark-utils STATIC "")
add_subdirectory(Spark/Utils)

if (GTEST_UNITTEST)
    add_subdirectory(unittest)
endif()

add_subdirectory(Apps/HttpServer)
add_subdirectory(Apps/ZKClient)

install(TARGETS spark-net
    ARCHIVE DESTINATION ${CMAKE_INSTALL_DIR}
    PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}/Net
    PRIVATE_HEADER DESTINATION include/${PROJECT_NAME}/Net/Impl
)

install(TARGETS spark-utils
    ARCHIVE DESTINATION ${CMAKE_INSTALL_DIR}
    PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}/Utils
)